package com.libweb.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.libweb.model.dao.BookDao;
import com.libweb.model.dto.Book;

@WebServlet("/book/editform.action")
public class BookEditFormServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		int bookNo = Integer.parseInt(request.getParameter("bookno"));
		
		BookDao dao = new BookDao();
		Book book = dao.getBookByBookNo(bookNo);
			
		request.setAttribute("book", book);
		
		RequestDispatcher dispatcher = 
			request.getRequestDispatcher("/WEB-INF/views/book/editform.jsp");

		dispatcher.forward(request, response);
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
